package com.cubeofnine.sugar.service.element;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.ksoap2.serialization.SoapObject;

public class ReturnExportContactList {
	private int total_contact;
	private List<Contact> contacts = new Vector<Contact>();
	private ErrorValue error;

	public ReturnExportContactList() {
		super();
	}

	public ReturnExportContactList(SoapObject obj) {
		try {
			String total_contact = obj.getProperty("total_contact").toString();
			this.total_contact = Integer.parseInt(total_contact, 10);
		} catch (Exception e) {
			this.total_contact = -1;
		}

		try {
			List<?> list = (Vector<?>) obj.getProperty("contacts");
			if (list != null) {
				Iterator<?> iter = list.iterator();
				while (iter.hasNext()) {
					addContact(new Contact((SoapObject) iter.next()));
				}
			}
		} catch (Exception e) {
			this.contacts = null;
		}

		try {
			this.error = new ErrorValue((SoapObject) obj.getProperty("error"));
		} catch (Exception e) {
			this.error = null;
		}
	}

	public ReturnExportContactList(int total_contact, List<Contact> contacts,
			ErrorValue error) {
		super();
		this.total_contact = total_contact;
		this.contacts = contacts;
		this.error = error;
	}

	public int getTotal_contact() {
		return total_contact;
	}

	public void setTotal_contact(int total_contact) {
		this.total_contact = total_contact;
	}

	public List<Contact> getContacts() {
		return contacts;
	}

	public void setContacts(List<Contact> contacts) {
		this.contacts = contacts;
	}

	public void addContact(Contact contact) {
		this.contacts.add(contact);
	}

	public ErrorValue getError() {
		return error;
	}

	public void setError(ErrorValue error) {
		this.error = error;
	}

}
